<?php

//
// File to load castle levels
//

$map = (int) $_REQUEST['map']; 
$mapInfo = "";
if ($map && file_exists('levels/'.$map)) {
  $handle = fopen('levels/'.$map, 'r');
  if ($handle) {
    $mapInfo = fread($handle, 702);
  }
  
  // explode map
  if ($mapInfo) {
    $mapLines = Array();
    $lines = explode("\n", $mapInfo);
    foreach($lines as $num => $str) {
      for ($x=0;$x<strlen($str);$x++) {
        $mapLines[ $num ][ $x ] = $str[ $x ];
      }
    }
    
    echo json_encode($mapLines);
  }
}

?>
